<?php
/**
 * Created by PhpStorm.
 * User: 小灰灰
 * Date: 2021-06-09
 * Time: 16:33:53
 * Info:
 */

namespace app\common\model;

class AuthGroupAccess extends TimeInit
{

    /**
     * 更新角色组
     *
     * @param $admin_id   string 管理员id
     * @param $group_id   array 角色组id
     * @param $type       string 如果有值，不做处理
     *
     * @return void
     */
    public static function updateGroupAccess($admin_id, $group_id = [], $type = '')
    {
        //先删除所有规则
        if (empty($admin_id)) {
            return false;
        }
        if ( ! empty($type)) {
            return false;
        }
        self::where('uid', $admin_id)->where('uid', '<>', 1)->delete();
        //然后重新写入
        if (empty($group_id)) {
            return true;
        }
        $data = [];
        foreach ($group_id as $g) {
            $data1['uid']      = $admin_id;
            $data1['group_id'] = $g;
            $data[]            = $data1;
        }
        self::insertAll($data);

        return true;
    }
}
